using System.Collections.Generic;
using System.Windows;
using System;

namespace Silvery.Logs
{
    public class LogItem
    {
        public LogItem()
        {
            Time  = DateTime.Now;
        }
        public DateTime Time { get;internal set; }
        public string Message { get;internal set; }
        public string ClassName { get; internal set; }
        public override string ToString()
        {
            return " " + Time.ToString() +" "+ ClassName + " " + Message;
        }
    }
    /// <summary>
    /// 调试日志信息类
    /// </summary>
    public sealed class NDebugLogs : List<LogItem>
    {
        /// <summary>
        /// 最大记录数，默认为200
        /// </summary>
        public static int MaxLogsSum { get; set; }
        private NDebugLogs()
        {
            MaxLogsSum = 200;
        }
        private static NDebugLogs _this;
        public static NDebugLogs Current
        {
            get
            {
                if (_this == null)
                    _this = new NDebugLogs();
                return _this;
            }
        }
        /// <summary>
        /// 添加调试日志信息
        /// </summary>
        /// <param name="message"></param>
        /// <param name="classname"></param>
        public void Add(string message, string classname)
        {
            if (Count >= MaxLogsSum)
                this.RemoveAt(0);
            base.Add(new LogItem() { ClassName = classname, Message = message });
           
        }
        public void Add(string message, object sender)
        {
            Add(message, sender.GetType().Name);
        }
    }
}
